package com.ztf.shopping.web.servlet;

import com.ztf.shopping.bean.User;
import com.ztf.shopping.service.UserService;
import com.ztf.shopping.service.imp.UserServiceImp;
import com.ztf.shopping.untils.SendEmail;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;
import java.io.IOException;
import java.util.HashMap;
import java.util.Map;

@WebServlet("/registerServlet")
public class RegisterServlet extends HttpServlet {
    protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        response.setContentType("text/html;charset=utf-8");
        String name = request.getParameter("nameID");
        String pwd = request.getParameter("pwd");
        String email = request.getParameter("email");


        UserService userService = new UserServiceImp();
        User user = new User(name,pwd,email);


        HttpSession session = request.getSession();
        session.setAttribute("userReg",user);

        System.out.println("----"+session.getId());

        SendEmail.send(email,name);

        userService.registerServlet(user);



    }

    protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        this.doPost(request, response);
    }
}
